package com.njust.utils;

import java.util.Collections;
import java.util.List;

public class PageUtil {
    public static List pagingUtil(Paging  paging,List list){
        int fromIndex = paging.getQueryIndex();
        int toIndex = 0;
        if (fromIndex + paging.getPageSize() >= list.size()){
            toIndex = list.size();
        }else {
            toIndex = fromIndex +  paging.getPageSize();
        }
        if (fromIndex > toIndex){
            return Collections.EMPTY_LIST;
        }
        return list.subList(fromIndex,toIndex);

    }
}
